{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 7.19 Water"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Water at 60 deg F flows from a reservoir through a piping system according to a diagram in the book. The reservoir has a head of 11.5 feet.\n",
    "\n",
    "The system is:\n",
    "\n",
    "    entrance\n",
    "    \n",
    "    3\" miter bend\n",
    "    \n",
    "    standard gate valve open\n",
    "    \n",
    "    10 feet of 3 inch pipe (sched 40)\n",
    "    \n",
    "    sudden contraction\n",
    "    \n",
    "    20 feet of 2 inch pipe (sched 40)\n",
    "    \n",
    "    exit\n",
    "\n",
    "Find the flow rate in gallons/minute."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "136.70828839615876 gallon/minute"
      ],
      "text/latex": [
       "$136.70828839615876\\ \\frac{\\mathrm{gallon}}{\\mathrm{minute}}$"
      ],
      "text/plain": [
       "136.70828839615876 <Unit('gallon / minute')>"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from fluids.units import *\n",
    "from math import pi\n",
    "L1 = 10*u.foot\n",
    "L2 = 20*u.foot\n",
    "\n",
    "dH = 11.5*u.foot\n",
    "\n",
    "mu = 1.1*u.cP\n",
    "rho = 62.364*u.lb/u.ft**3\n",
    "\n",
    "NPS1, Di1, Do1, t1 = nearest_pipe(NPS=3, schedule='40')\n",
    "NPS2, Di2, Do2, t2 = nearest_pipe(NPS=2, schedule='40')\n",
    "\n",
    "A1 = 0.25*pi*Di1**2\n",
    "A2 = 0.25*pi*Di2**2\n",
    "\n",
    "ft1 = ft_Crane(Di1)\n",
    "ft2 = ft_Crane(Di2)\n",
    "\n",
    "roughness = 0.0018*u.inch\n",
    "\n",
    "dP = rho*dH*1*u.gravity\n",
    "\n",
    "fd1 = fd2 = 0.018 # assumed; solve with sequential substitution\n",
    "# Take the 3\" diameter as the reference for K\n",
    "for i in range(10):\n",
    "    K_entrance = entrance_sharp(method='Crane')\n",
    "    K_exit = change_K_basis(exit_normal(), 2*u.inch, 3*u.inch)\n",
    "    K_gate = K_gate_valve_Crane(D1=Di1, D2=Di1, angle=0.0*u.degrees)\n",
    "    K_elbow = bend_miter(Di=Di1, angle=90*u.degrees, method='Crane')\n",
    "    K_contraction = change_K_basis(contraction_conical_Crane(3*u.inch, 2*u.inch, l=0*u.m), 2*u.inch, 3*u.inch)\n",
    "\n",
    "    K_tot = K_entrance + K_elbow + K_gate + K_exit + K_contraction\n",
    "    K_f1 = K_from_f(fd=fd1, L=L1, D=Di1)\n",
    "    K_f2 = change_K_basis(K_from_f(fd=fd2, L=L2, D=Di2), 2*u.inch, 3*u.inch) \n",
    "    K_tot += K_f1 + K_f2\n",
    "    \n",
    "    K_tot_basis2 = change_K_basis(K_tot, 3*u.inch, 2*u.inch)\n",
    "    \n",
    "    v1 = (2*dP/(K_tot*rho))**0.5\n",
    "    v2 = (2*dP/(K_tot_basis2*rho))**0.5\n",
    "\n",
    "    Re1 = rho*v1*Di1/mu\n",
    "    Re2 = rho*v2*Di2/mu\n",
    "    fd1 = friction_factor(Re=Re1, eD=roughness/Di1)\n",
    "    fd2 = friction_factor(Re=Re2, eD=roughness/Di2)\n",
    "\n",
    "Q = A1*v1\n",
    "Q.to(u.gal/u.min)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The solution given in Crane where they also perform iterations is 137 gal/min."
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
